home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / tmp / customization-scripts / gui.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  2009-02-04  |  5KB  |  181 lines

  1. #!/bin/bash
  2.  
  3. ###################################################################################
  4. # UCK - Ubuntu Customization Kit                                                  #
  5. # Copyright (C) 2006-2009 UCK Team                                                #
  6. #                                                                                 #
  7. # UCK is free software: you can redistribute it and/or modify                     #
  8. # it under the terms of the GNU General Public License as published by            #
  9. # the Free Software Foundation, either version 3 of the License, or               #
  10. # (at your option) any later version.                                             #
  11. #                                                                                 #
  12. # UCK is distributed in the hope that it will be useful,                          #
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of                  #
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                   #
  15. # GNU General Public License for more details.                                    #
  16. #                                                                                 #
  17. # You should have received a copy of the GNU General Public License               #
  18. # along with UCK.  If not, see <http://www.gnu.org/licenses/>.                    #
  19. ###################################################################################
  20.  
  21. function find_dialog()
  22. {
  23.     if [ ! -z "$DISPLAY" ] ; then
  24.         DIALOG=`which kdialog`
  25.  
  26.         if [ ! -z "$DIALOG" ]; then
  27.             DIALOG_TYPE=kdialog
  28.         else
  29.             DIALOG=`which Xdialog`
  30.  
  31.             if [ ! -z "$DIALOG" ]; then
  32.                 DIALOG_TYPE=dialog
  33.             fi
  34.         fi
  35.  
  36.         if [ -z "$DIALOG" ]; then
  37.             DIALOG=`which zenity`
  38.  
  39.             if [ ! -z "$DIALOG" ]; then
  40.                 DIALOG_TYPE=zenity
  41.             fi
  42.         fi
  43.     fi
  44.  
  45.     if [ -z "$DIALOG" ]; then
  46.         DIALOG=`which dialog`
  47.  
  48.         if [ ! -z "$DIALOG" ]; then
  49.             DIALOG_TYPE=dialog
  50.         fi
  51.     fi
  52.  
  53.     if [ -z $DIALOG ]; then
  54.         failure "You need kdialog, Xdialog, dialog or zenity application to run this script, please install it using 'apt-get install packagename' where packagename is 'kdebase-bin' for kdialog, 'xdialog' for dialog, 'dialog' for dialog. If you are using text-mode, you need to install dialog."
  55.     fi
  56. }
  57.  
  58. function dialog_menu()
  59. {
  60.     DESCRIPTION="$1"
  61.     shift
  62.  
  63.     declare -a PARAMS
  64.  
  65.     if [ "$DIALOG_TYPE" = "zenity" ]; then
  66.         declare -i i=0
  67.         for v; do
  68.             PARAMS[$i]="$v"
  69.             i+=1
  70.         done
  71.         $DIALOG --list --text "$DESCRIPTION" --column "" "${PARAMS[@]}" --width=500 --height=400
  72.     else
  73.         if [ "$DIALOG_TYPE" = "kdialog" ] ; then
  74.             declare -i i=0
  75.             for v; do
  76.                 PARAMS[$i]="$v"
  77.                 i+=1
  78.                 PARAMS[$i]="$v" #yes, 2 times as kdialog requires key and value
  79.                 i+=1
  80.             done
  81.             $DIALOG --menu "$DESCRIPTION" "${PARAMS[@]}"
  82.         else
  83.             declare -i i=0
  84.             for v; do
  85.                 PARAMS[$i]="$v"
  86.                 i+=1
  87.                 PARAMS[$i]="Language"
  88.                 i+=1
  89.             done
  90.             $DIALOG --stdout --menu "$DESCRIPTION" 20 30 10 "${PARAMS[@]}"
  91.         fi
  92.     fi
  93. }
  94.  
  95. function dialog_multi_choice()
  96. {
  97.     DESCRIPTION="$1"
  98.     shift
  99.  
  100.     if [ "$DIALOG_TYPE" = "zenity" ]; then
  101.         for i; do
  102.             PARAMS="$PARAMS $i $i"
  103.         done
  104.         $DIALOG --separator $'\n' --list --checklist --multiple --text "$DESCRIPTION" --column "" --column ""  $PARAMS --width=500 --height=400
  105.     else
  106.         if [ "$DIALOG_TYPE" = "kdialog" ] ; then
  107.             for i; do
  108.                 PARAMS="$PARAMS $i $i 0"
  109.             done
  110.             $DIALOG --separate-output --checklist "$DESCRIPTION" $PARAMS
  111.         else
  112.             for i; do
  113.                 PARAMS="$PARAMS $i Language 0"
  114.             done
  115.             $DIALOG --stdout --separate-output --checklist "$DESCRIPTION" 20 30 10 $PARAMS
  116.         fi
  117.     fi
  118.  
  119.     RESULT=$?
  120.     return $RESULT
  121. }
  122.  
  123. function dialog_line_input()
  124. {
  125.     DESCRIPTION="$1"
  126.     INITIAL_VALUE="$2"
  127.  
  128.     if [ "$DIALOG_TYPE" = "zenity" ] ; then
  129.         $DIALOG --entry --text "$DESCRIPTION" --entry-text "$INITIAL_VALUE"
  130.     else
  131.         if [ "$DIALOG_TYPE" = "kdialog" ] ; then
  132.             $DIALOG --inputbox "$DESCRIPTION" "$INITIAL_VALUE"
  133.         else
  134.             $DIALOG --stdout --inputbox "$DESCRIPTION" 20 30 "$INITIAL_VALUE"
  135.         fi
  136.     fi
  137.  
  138.     RESULT=$?
  139.     return $RESULT
  140. }
  141.  
  142. function dialog_choose_file()
  143. {
  144.     TITLE="$1"
  145.  
  146.     if [ "$DIALOG_TYPE" = "zenity" ] ; then
  147.         $DIALOG --title "$TITLE" --file-selection "`pwd`/"
  148.     else
  149.         if [ "$DIALOG_TYPE" = "kdialog" ] ; then
  150.             $DIALOG --title "$TITLE" --getopenfilename "`pwd`/"
  151.         else
  152.             $DIALOG --stdout --title "$TITLE" --fselect "`pwd`/" 10 70
  153.         fi
  154.     fi
  155. }
  156.  
  157. function dialog_msgbox()
  158. {
  159.     TITLE="$1"
  160.     TEXT="$2"
  161.  
  162.     if [ "$DIALOG_TYPE" = "zenity" ]; then
  163.         echo -n "$TEXT" | $DIALOG --title "$TITLE" --text-info --width=500 --height=400
  164.     else
  165.         $DIALOG --title "$TITLE" --msgbox "$TEXT" 20 80
  166.     fi
  167. }
  168.  
  169. function dialog_question()
  170. {
  171.     TITLE="$1"
  172.     TEXT="$2"
  173.  
  174.     if [ "$DIALOG_TYPE" = "zenity" ]; then
  175.         $DIALOG --title "$TITLE" --question --text "$TEXT"
  176.     else
  177.         $DIALOG --title "$TITLE" --yesno "$TEXT" 20 80
  178.     fi
  179. }
  180.  
  181. find_dialog